package com.ruanjian2001.controller;

import com.ruanjian2001.Service.OrderService;
import com.ruanjian2001.entity.Order;
import com.ruanjian2001.entity.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 根据用户查询所属订单
 */
public class findOrderByUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取名字为user的session
        User user = (User) request.getSession().getAttribute("user");
        System.out.println("------------------");
        System.out.println(user);

        //调用service中方法
        OrderService service = new OrderService();
        List<Order> orders = service.findOrderByUser(user);

        System.out.println("数组的个数"+orders.size());

        //将orders数组存到session中
        request.setAttribute("orders", orders);
        request.getRequestDispatcher("/client/orderlist.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request,response);
    }
}
